module xenForces;

import blaze.dynamics.forces.bzForceGenerator;
import blaze.dynamics.bzBody;
import blaze.common.bzMath;

public class xenDrive : bzForceGenerator {
    /**
     * velocity drag coefficient
     */
    float k1;

    /**
     * velocity squared drag coefficient
     */
    float maxForce;
	float tx,ty;
	bzVec2 point,force;

    this (bzBody rBody, float[2] iTarget,float[2] iPt,float maxForce) {
	    super(rBody);
		tx=iTarget[0];
        ty=iTarget[1];
		point.set(iPt[0],iPt[1]);
        this.maxForce=maxForce;
    }

    override void evaluate() {
		float X,Y,N;
		X=tx-rBody.position.x;
		Y=ty-rBody.position.y;
		N=sqrt(X*X+Y*Y);
		float F=min(N,maxForce)/N;
		//force.set(X*F,Y*F);
		force.set(1,1.0);
        
        float degtorad=3.141592f/180f;
        rBody.force += force.rotate(rBody.angle*degtorad);
		/*rBody.torque += (bzCross(point.rotate(rBody.angle*degtorad),
                             force.rotate(rBody.angle*degtorad)))*0.001f;
		*/
    }
}